package com.lhd.qd.module.system.dict.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lhd.qd.common.base.ApiResult;
import com.lhd.qd.common.base.BaseController;
import com.lhd.qd.common.base.BasePageQuery;
import com.lhd.qd.module.system.dict.model.dto.DictTypeSaveDTO;
import com.lhd.qd.module.system.dict.model.dto.DictTypeUpdateDTO;
import com.lhd.qd.module.system.dict.model.vo.DictTypeDetailVO;
import com.lhd.qd.module.system.dict.model.vo.DictTypeListVO;
import com.lhd.qd.module.system.dict.service.DictTypeService;
import com.lhd.qd.module.system.dict.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "字典类型")
@RequestMapping("dict-type")
@RestController
public class DictTypeController extends BaseController {

    @Autowired
    private DictTypeService dictTypeService;

    @ApiOperation(value = "分页列表", response = DictTypeListVO.class)
    @GetMapping
    public ResponseEntity<ApiResult<IPage<DictTypeListVO>>> pageDictType(BasePageQuery query) {

        return success(dictTypeService.pageDictType(query));
    }

    @ApiOperation(value = "详情", response = DictTypeDetailVO.class)
    @GetMapping("{code}")
    public ResponseEntity<ApiResult<DictTypeDetailVO>> getDictTypeById(@PathVariable("code") String code) {

        return success(dictTypeService.getDictTypeById(code));
    }

    @ApiOperation(value = "新增")
    @PostMapping
    public ResponseEntity<ApiResult> saveDictType(@Validated @RequestBody DictTypeSaveDTO saveDTO) {

        return successOrFail(dictTypeService.saveDictType(saveDTO));
    }

    @ApiOperation(value = "修改")
    @PutMapping("{code}")
    public ResponseEntity<ApiResult> updateDictTypeById(@PathVariable("code") String code, @Validated @RequestBody DictTypeUpdateDTO updateDTO) {

        return successOrFail(dictTypeService.updateDictTypeById(code, updateDTO));
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("{code}")
    public ResponseEntity<ApiResult> removeDictTypeById(@PathVariable("code") String code) {

        return successOrFail(dictTypeService.removeDictTypeById(code));
    }
}
